<template>
  <div :id="containerId" class="editor-container">
    <slot v-if="g6Utils" />
  </div>

</template>

<script>
import G6Utils from '@/components/FlowEditor/G6Utils';
import G6 from '@antv/g6';
export default {
  name: 'FlowEditor',
  props: {
    G6Utils: {
      type: Function,
      required: false,
      default: G6Utils
    },
    containerId: {
      type: String,
      required: true,
      default: 'flowEditorContainer'
    },
    options: {
      type: Object,
      required: false,
      default: () => ({})
    }
  },
  data() {
    return {
      g6Utils: null
    };
  },

  mounted() {
    this.init();
  },
  methods: {
    init() {
      const width = document.querySelector(`#${this.containerId}`).clientWidth;
      const height = document.querySelector(`#${this.containerId}`).clientHeight;
      this.g6Utils = new this.G6Utils().initEditor(this.containerId, Object.assign({ width, height }, this.options));
    }
  }
};
</script>

<style scoped lang="scss">
.editor-container{
  width: 100%;
  height: 100%;
  position: relative;
}
</style>
<style lang="scss">
  .g6-tooltip,.g6-node-tooltip {
    padding: 10px 6px;
    color: #444;
    background-color: rgba(255, 255, 255, 1);
    border: 1px solid #e2e2e2;
    border-radius: 4px;
    font-size: 12px;
  }
</style>
